#ifndef EZLOGGER_FORMAT_POLICY_HPP_HEADER_GRD_
#define EZLOGGER_FORMAT_POLICY_HPP_HEADER_GRD_

#include <string>
#include <stdio.h>
#include <time.h>

#include "ezlogger_misc.hpp"

namespace axter
{
	/*! @class ezlogger_format_policy
	@brief This struct defines the get_log_prefix_format function, which 
			is used to format the start of each log line.
	The default ezlogger_format_policy only uses one variable member from
	the ext_data struct (m_severity_level).   A custom format policy could
	take advantage of the additional variables and use them to out put
	more detailed structured data.
	@note
		The get_current_time_str method is not required when creating a
		custom format policy.
	*/
	class ezlogger_format_policy
	{
	public:
		inline static std::string get_log_prefix_format(const char*FileName, 
			int LineNo, const char*FunctionName, ext_data levels_format_usage_data)
		{
			std::string FileNameOnly = FileName;
			size_t pos = FileNameOnly.rfind('\\');
			if (pos != std::string::npos)
			{
				FileNameOnly = FileNameOnly.substr(pos+1);
			}
			char FileNameFormat[999] = {0};
			char *lev;
			switch(levels_format_usage_data.m_severity_level)
			{
			case no_severity:
				lev = "MSG";
				break;
			case debug:
				lev = "DEBUG";
				break;
			case info:
				lev = "INFO";
				break;
			case status:
				lev = "STATUS";
				break;
			case warn:
				lev = "WARN";
				break;
			case error:
				lev = "ERROR";
				break;
			case fatal:
				lev = "FATAL";
				break;
			}
			sprintf(FileNameFormat, "%s[%-6s]-%s(%i){%s}:\t", 
				 get_current_time_str().c_str(), lev,FileNameOnly.c_str(), LineNo, FunctionName);

			return FileNameFormat;
		}
	private:
		inline static std::string get_current_time_str()
		{
			time_t t = time(0) ;
            char buff[20];
            time_t now = time(NULL);
            strftime(buff, 20, "%H:%M:%S", localtime(&now));
            std::string tmp(buff);
			return tmp;
		}
	};
}

#endif //EZLOGGER_FORMAT_POLICY_HPP_HEADER_GRD_
